<%@page import="transfer.Commodity"%>
<%@page import="content.CommodityContent"%>

<%
    int id = 1;
    double price = 0;
    try {
        String idParameter = request.getParameter("id");
        if (idParameter != null) {
            id = Integer.parseInt(idParameter);
        }
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
%>
    <script>
        window.location.replace('index.jsp');
    </script>
<%
        return;
    } catch (NullPointerException npe) {
        npe.printStackTrace();
%>
    <script>
        window.location.replace('index.jsp');
    </script>
<%
        return;
    }    
%>
<%  
    Commodity commodity = null;
    try {
         commodity = CommodityContent.getCommodity(new Integer(id));
    } catch(Exception exc) {
%>
    <script>
        window.location.replace('index.jsp');
    </script>
<%
        return;
    }
    if (commodity == null) {
       
%>
    <script>
        window.location.replace('index.jsp');
    </script>
<%        
        return;
    }
    String imagePath = "images/commodity/" + commodity.getImage();
%>
<div class="img-big-view">
    <div class="float_left">
        <img src="<% out.print(imagePath);%>">
    </div>
</div>
<div class="float_left" style="width: 620px" >
    <div class="block-header-item">
        <H2><% out.print(commodity.getNameCommodity());%></H2>
    </div>
    <div style="margin-top: 15px;">
        <H3>Price:
            <span class="price">
                <%
                    price = commodity.getPrice().doubleValue();
                    if ((Math.round(price) - price) == 0) {
                        out.print((int) price + " $");
                    } else {
                        out.print(price + " $");
                    }
                %> 
            </span> 
        </H3> 
    </div>
    <%
        if (!commodity.getOutOfProduction().booleanValue()) {
    %>
        <div style="margin-top: 15px;">
            <input type="button" value="buy" class="input" onclick="addCommodity( <%= new Integer(id).intValue() %>)" />
        </div>
    <%
        }
    %>
</div>


<div class="description">
    <% out.print(commodity.getDescription());%>
</div>
